﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Hr.Entity;
namespace Chenxin.Lib.Hr.BLL
{
    /// <summary>
    /// 业务逻辑类Hr_PersonnelTransferInfo 的摘要说明。
    /// </summary>
    public class Hr_PersonnelTransferInfo
    {

        //Cache服务类
        private Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.HR);

        public Hr_PersonnelTransferInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo model)
        {
            //调动信息键
            string strKeyTransferInfo = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_TRANSFERINFO, model.UserId.ToString());
            cs.Delete(strKeyTransferInfo);
            Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo model)
        {
            //调动信息键
            string strKeyTransferInfo = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_TRANSFERINFO, model.UserId.ToString());
            cs.Delete(strKeyTransferInfo);
            Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.GetModel(RecordId);
        }

        /// <summary>
        /// 通过用户Id得到实体列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo> GetModelListByUserId(Guid UserId)
        {
            //调动信息键
            string strKeyTransferInfo = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_TRANSFERINFO, UserId.ToString());
            //调动信息列表
            List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo> lsTransferInfo;
            //Cache中取得调动信息
            lsTransferInfo= cs.GetList<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo>(strKeyTransferInfo);

            //未命中
            if (!cs.Hit)
            {
                string strWhere;

                strWhere = " UserId = '" + UserId.ToString() +"'";

                lsTransferInfo = new List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo>();
                //数据库中查找
                lsTransferInfo = Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.GetListArray(strWhere);
                //加入到Cache中
                cs.Set(strKeyTransferInfo, lsTransferInfo);
            }

            return lsTransferInfo;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.GetList(strWhere);
        }
        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top, string strWhere, string filedOrder)
        //{
        //    return Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.GetList(Top, strWhere, filedOrder);
        //}
        ///// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Hr.DAL.Hr_PersonnelTransferInfo.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo> modelList = new List<Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Hr.Entity.Hr_PersonnelTransferInfo();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    if (dt.Rows[n]["UserId"].ToString() != "")
                    {
                        model.UserId = new Guid(dt.Rows[n]["UserId"].ToString());
                    }
                    model.UserName = dt.Rows[n]["UserName"].ToString();


                    if (dt.Rows[n]["CityId_O"].ToString() != "")
                    {
                        model.CityId_O = new Guid(dt.Rows[n]["CityId_O"].ToString());
                    }
                    model.City_O = dt.Rows[n]["City_O"].ToString();
                    if (dt.Rows[n]["CompanyId_O"].ToString() != "")
                    {
                        model.CompanyId_O = new Guid(dt.Rows[n]["CompanyId_O"].ToString());
                    }
                    model.Company_O = dt.Rows[n]["Company_O"].ToString();


                    if (dt.Rows[n]["DepartId_O"].ToString() != "")
                    {
                        model.DepartId_O = new Guid(dt.Rows[n]["DepartId_O"].ToString());
                    }
                    model.Depart_O = dt.Rows[n]["Depart_O"].ToString();
                    model.Position_O = dt.Rows[n]["Position_O"].ToString();
                    model.EmpLevel_O = dt.Rows[n]["EmpLevel_O"].ToString();

                    if (dt.Rows[n]["CityId_N"].ToString() != "")
                    {
                        model.CityId_N = new Guid(dt.Rows[n]["CityId_N"].ToString());
                    }
                    model.City_N = dt.Rows[n]["City_N"].ToString();
                    if (dt.Rows[n]["CompanyId_N"].ToString() != "")
                    {
                        model.CompanyId_N = new Guid(dt.Rows[n]["CompanyId_N"].ToString());
                    }
                    model.Company_N = dt.Rows[n]["Company_N"].ToString();

                    if (dt.Rows[n]["DepartId_N"].ToString() != "")
                    {
                        model.DepartId_N = new Guid(dt.Rows[n]["DepartId_N"].ToString());
                    }
                    model.Depart_N = dt.Rows[n]["Depart_N"].ToString();
                    model.Position_N = dt.Rows[n]["Position_N"].ToString();
                    model.EmpLevel_N = dt.Rows[n]["EmpLevel_N"].ToString();
                    model.TransType = dt.Rows[n]["TransType"].ToString();
                    model.TransReason = dt.Rows[n]["TransReason"].ToString();
                    if (dt.Rows[n]["TransTime"].ToString() != "")
                    {
                        model.TransTime = DateTime.Parse(dt.Rows[n]["TransTime"].ToString());
                    }
                    if (dt.Rows[n]["AddTime"].ToString() != "")
                    {
                        model.AddTime = DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
                    }
                    model.AddPerson = dt.Rows[n]["AddPerson"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

